package demo1;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //最长公共前缀
    public String longestCommonPrefix(String[] strs) {
        if(strs.length==0)return "";
        //公共前缀比所有字符串都短，随便选一个先
        String s=strs[0];
        for (String string : strs) {
            while(!string.startsWith(s)){
                if(s.length()==0)return "";
                //公共前缀不匹配就让它变短！
                s=s.substring(0,s.length()-1);
            }
        }
        return s;
    }


    //最长公共前缀
    public String longestCommonPrefix1(String[] strs) {
        StringBuilder ret = new StringBuilder();
        int len = strs.length;
        while(true) {
            for (int i = 0; i < len; i++) {
                for (int j = 0; j < len; j++) {

                }
            }
        }
    }

    public static void main(String[] args) {
        countAndSay(4);
    }

    public static void main1(String[] args) {
        System.out.println('a'=='a');
    }

    //外观数列
    public static String countAndSay(int n) {
        String ret = "1";
        for (int i = 1; i < n; i++) {
            StringBuilder tmp = new StringBuilder();
            for (int left=0,right=0;right<ret.length();) {
                while(right<ret.length() && ret.charAt(left)==ret.charAt(right))
                    right++;
                tmp.append(Integer.toString(right-left));
                tmp.append(ret.charAt(left));
                left = right;
            }
            ret = tmp.toString();
        }
        return ret;
    }

}
